package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.exception.BaseException;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements com.hmall.item.service.ItemService {


    @Autowired
    private ItemMapper itemMapper;

    @Override
    public void updateItem(Item item) {

        Item oldItem = itemMapper.selectById(item.getId());
        if (oldItem != null && oldItem.getStatus() == 1) { throw new BaseException("商品已上架，不能修改");
        }
        itemMapper.updateById(item);
    }

    @Override
    public void deleteItem(Long id) {
        Item item = itemMapper.selectById(id);
        if (item.getStatus() == 1) { throw new BaseException("商品已上架，不能删除");
        }
        itemMapper.deleteById(id);
    }

    @Override
    public Item queryItemById(Long id) {
        return null;
    }

//    @Override
//    public Item queryItemById(Long id) {
//        if (id == null) {
//
//        }
//
//}
}
